import Http from "../../../utils/http.js";
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    colorMap: [{
        name: "黑色",
        color: "#000000"
      },
      {
        name: "白色",
        color: "#fff"
      },
      {
        name: "灰色",
        color: "#bfbfbf"
      },
      {
        name: "深色",
        color: "#535353"
      },
      {
        name: "香槟色",
        color: "#cfa972"
      },
      {
        name: "象牙色",
        color: "#ffffd6"
      },
      {
        name: "红色",
        color: "#e60012"
      },
      {
        name: "橙色",
        color: "#f39800"
      },
      {
        name: "蓝色",
        color: "#2236cc"
      },

      {
        name: "象牙白",
        color: "#fffff0"
      },

      {
        name: "银灰",
        color: "#c0c0c0"
      },
      {
        name: "黄色",
        color: "#fff45c"
      }
    ],
    info: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    /**
     * 获取运营的性质字典
     */
    Http.request({
      url: '/dict/findDict',
      method: 'GET',
      data: {
        category: 'VEHICLE_COLOR',
      },
      success: (res) => {
        this.setData({
          info: this._getMapColor(res, this.data.colorMap)
        })
      }
    });
  },

  _getMapColor(arr, colorMap) {
    arr.forEach((item1, index1, self1) => {
      colorMap.forEach((item2, index2, self2) => {
        if(item1.name==item2.name){
          item1.color=item2.color;
        }
      });
    });
   
    return arr;
  },

  bindChooseColor:function(e){
    let dataSet=e.currentTarget.dataset;
    let pages = getCurrentPages();
    let prevPage = null; //上一个页面
    if (pages.length >= 2) {
      prevPage = pages[pages.length - 2]; //上一个页面
    }
    prevPage && prevPage.pageCarColorChooseColor(this.data.info[dataSet.idx]);
    wx.navigateBack();


  }
})